package com.lee.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;


/**
 * es配置
 * 构造restHighLevelClient 实例到spring容器.
 *
 * @author winston
 * @date 2022/03/15
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Configuration
@Data
public class EsConfiguration extends AbstractElasticsearchConfiguration {
    private String url;
    @Override
    public RestHighLevelClient elasticsearchClient() {
        return new RestHighLevelClient(RestClient.builder(HttpHost.create(url)));
    }
}
